<template>
  <div class="activity-card" @click="$emit('click')">
    <!-- 图片容器 -->
    <div class="card-image-container">
      <img 
        :src="activity.imageUrl" 
        class="card-image" 
        :style="{ height: `${activity.imageHeight}px` }"
        @load="handleImageLoaded"
      />
      <!-- 图片计数 -->
      <div class="card-image-count" v-if="activity.imageCount">
        {{ activity.imageCount }}
      </div>
    </div>
    
    <!-- 内容区域 -->
    <div class="card-content">
      <!-- 标题 -->
      <div class="card-title">{{ activity.title }}</div>
      
      <!-- 描述 -->
      <div class="card-description">{{ activity.description }}</div>
      
      <!-- 底部信息 -->
      <div class="card-footer">
        <!-- 用户头像和位置信息 -->
        <div class="card-user-info">
          <img v-if="activity.hasAvatar" :src="activity.avatarUrl" class="user-avatar" />
          <div class="location-info">
            <span class="location-icon">📍</span>
            <span>{{ activity.city }} {{ activity.district }}</span>
          </div>
        </div>
        
        <!-- 日期和互动信息 -->
        <div class="card-interaction">
          <div class="date-info">{{ activity.date }}</div>
          <div class="interaction-icons">
            <span class="like-icon">❤️ {{ activity.likes || 0 }}</span>
            <span class="comment-icon">💬 {{ activity.comments || 0 }}</span>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue';

const props = defineProps({
  activity: {
    type: Object,
    required: true
  }
});

const emit = defineEmits(['image-loaded', 'click']);

const handleImageLoaded = (event) => {
  // 获取图片实际尺寸
  const { naturalWidth, naturalHeight } = event.target;
  
  // 发送图片加载完成事件
  emit('image-loaded', {
    id: props.activity.id,
    dimensions: {
      width: naturalWidth,
      height: naturalHeight
    }
  });
};
</script>

<style scoped>
.activity-card {
  width: 100%;
  background-color: #ffffff;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
  transition: all 0.25s ease;
  display: flex;
  flex-direction: column;
  cursor: pointer;
  margin-bottom: 8px;
  height: 100%; /* 确保卡片填充整个容器高度 */
}

.activity-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.card-image-container {
  width: 100%;
  position: relative;
  overflow: hidden;
  border-radius: 8px 8px 0 0;
}

.card-image {
  width: 100%;
  display: block;
  object-fit: cover;
  transition: transform 0.5s;
}

.activity-card:hover .card-image {
  transform: scale(1.03);
}

.card-image-count {
  position: absolute;
  bottom: 8px;
  right: 8px;
  background-color: rgba(0, 0, 0, 0.5);
  color: white;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 500;
}

.card-content {
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  flex: 1;
}

.card-title {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 6px;
  line-height: 1.3;
  color: #333;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-description {
  font-size: 12px;
  color: #666;
  margin-bottom: 10px;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-footer {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.card-user-info {
  display: flex;
  align-items: center;
  gap: 8px;
}

.user-avatar {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  object-fit: cover;
}

.location-info {
  display: flex;
  align-items: center;
  font-size: 11px;
  color: #999;
}

.location-icon {
  font-size: 10px;
  margin-right: 2px;
}

.card-interaction {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.date-info {
  font-size: 11px;
  color: #999;
}

.interaction-icons {
  display: flex;
  gap: 8px;
  font-size: 11px;
  color: #999;
}

.like-icon, .comment-icon {
  display: flex;
  align-items: center;
  gap: 2px;
}
</style>








